﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataModel;
using System.Web.Mvc;
using ChurchEdu.Models;
namespace ChurchEdu.Lib
{
    public class ResourceBL:IResource
    {
        private Church_DataEntities db;      
        private ModelStateDictionary _errg;

        public ResourceBL(ModelStateDictionary ModelState) 
        {
            db = new Church_DataEntities();
            _errg = ModelState;
        }
        public ResourceBL()
        {
            db = new Church_DataEntities();

        }
        //public int GetCommentCountByprojectSN(string projectSN) 
        //{
        //    return (from a in db.Feedbacks where a.ProjectSN == projectSN select a).Count();
        //    //db.Feedbacks.Select(a => a.ProjectSN == projectSN).Count();   
        //}
        //public decimal GetAverageStarvalueByprojectSN(string projectSN) 
        //{
        //    decimal averagestarvalue;
        //  int toalstarvalue=0;
        //  float  i=0;
        //  db.Feedbacks.Where(a=>a.ProjectSN==projectSN).ToList().ForEach(a=>
        //  {
        //      if (a.StarValue !=0) {
        //          toalstarvalue += Convert.ToInt16(a.StarValue);
        //          i++;
              
        //      };
        //  });
        //  if (toalstarvalue == 0)
        //  {
        //      decimal aa = 0;
        //      return aa;

        //  }
        //  else {
        //      averagestarvalue = Convert.ToDecimal(toalstarvalue / i);

        //      return decimal.Round(averagestarvalue, 1);     
          
        //  }

           
        //}

      // public bool HaveCommentByprojectSN(string projectSN)
      //   {
      //       if ((from a in db.Feedbacks where a.ProjectSN==projectSN select a).Count() >0) return true;
      //       else return false;
         
      //   }
      //public  void DeleteCommentByprojectSN(string projectSN) 
      // {

      //     db.Feedbacks.Where(a => a.ProjectSN == projectSN).ToList().ForEach(a =>
      //    {
      //        db.Feedbacks.Remove(a);
      //    });
      //     db.SaveChanges();
      // }

        public void ManageCreate(string title,string subtitle ,string describe, string location, int userid)
      {
          Resource Addresource = new Resource 
          {
                 Title=title,
                 SubTitle=subtitle, 
                 Descrb=describe,
                Location=location,
                DateTimeStamp=DateTime.Now,
                UserID=userid,
          };
          db.Resource.Add(Addresource);
          db.SaveChanges();
      
      }

    public void ManageCreateImageFile(UploadResourceFile model)
    {
        Resource fileresource = new Resource
        {
            ResCheck = model.checkornot,
            ImageshotFileName = model.Uploadimage,
            PackageFileName = model.UploadFile,
        };
        db.Resource.Add(fileresource);
        db.SaveChanges();

    }




        public IQueryable<Resource> GetResourceList(int videoId)
      {
          return db.Resource.OrderByDescending(a => a.DateTimeStamp);      
      }






    }
}